//
//  SEGActivityTriggerViewController.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/8/17.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGActivityTriggerViewController.h"
#import "SEGActivityDetailUsersCell.h"
#import "SEGActivitySignViewController.h"

@interface SEGActivityTriggerViewController ()

@end

@implementation SEGActivityTriggerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 重置展示数据
    self.displayTypeArray = @[@(SEGActivityDetailCellDispalyType_Rule), @(SEGActivityDetailCellDispalyType_TencentAD), @(SEGActivityDetailCellDispalyType_JoinedUser),  @(SEGActivityDetailCellDispalyType_Comment)];
    [self.tableView registerClass:[SEGActivityDetailUsersCell class] forCellReuseIdentifier:kActivityDetailUsersCellIdentifier];
}

#pragma mark - 根据不同类型活动进行界面设置 子类根据需要重写
/// 请求详情后请求其他数据
- (void)requestOtherInfoAfterDetail {
    if([self.detailModel.triggerEvent isEqualToString:@"payManagementFee"]) {//物业缴费
        if ([self.detailModel.isReview isEqualToString:@"1"]) {//未开启留言板 不显示底部工具栏
            self.toolBarView.hidden = YES;
            [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
            }];
        }
    }
}

/// 返回section中的行数
- (NSInteger)setRowsInSection:(NSInteger)section {
    return 1;
}

/// 返回cell
- (UITableViewCell *)setCellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SEGActivityDetailUsersCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kActivityDetailUsersCellIdentifier forIndexPath:indexPath];
    [cell setUpCellWithModel:self.detailModel isOffLine:NO];
    return cell;
}

/// 设置cell高度
- (CGFloat)setHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}

#pragma mark - SEGActivityDetailToolBarDelegate
- (void)attendButtonAction {
    
    [self.detailViewModel.joinTriggerActivitySignal subscribeNext:^(id  _Nullable x) {
        /*
         triggerEvent包含：
         topic:参与话题
         reply-daily:回复日报
         purchanceProduct:购买商品
         postForHelp:帮帮发帖
         marktForHelp:集市发帖
         openDoor:手机开门
         payManagementFee:物业缴费
         */
        NSString *triggerEvent = self.detailModel.triggerEvent;
        if ([triggerEvent isEqualToString:@"topic"]) {//参与话题
            NSDictionary *dict = @{@"objId":self.detailModel.eventValue};
            UIViewController *NewTopicDetailVC = [[SEGUhomeMediator sharedInstance] seg_initTopicDetailViewController:dict];
            [self.navigationController pushViewController:NewTopicDetailVC animated:YES];
        }else if([triggerEvent isEqualToString:@"reply-daily"]) {//回复日报
            NSDictionary *params = @{@"pictorialId":self.detailModel.eventValue};
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initPGCDeteailViewController:params];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }else if([triggerEvent isEqualToString:@"purchanceProduct"]) {//购买商品
            NSDictionary *params = @{@"serviceId":self.detailModel.eventValue};
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initGroupsShoppingDetailViewController:params];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }else if([triggerEvent isEqualToString:@"postForHelp"]) {//帮帮发帖
            // 跳转到邻里圈
            [[SEGUhomeMediator sharedInstance]seg_selctedToTabWithAction:@"TAB_UGC"];
        }else if([triggerEvent isEqualToString:@"marktForHelp"]) {//集市发帖
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initMarketListViewController:nil];
            [self.navigationController pushViewController:vc animated:YES];
        }else if([triggerEvent isEqualToString:@"openDoor"]) {//手机开门
            [[SEGUhomeMediator sharedInstance] seg_showOPenDoorViewWithAction:nil];
        }else if([triggerEvent isEqualToString:@"payManagementFee"]) {//物业缴费
            //            [[NSNotificationCenter defaultCenter] postNotificationName:SEGActivityTriggerTONewPreferrendRootVCNotification object:nil];
        } else if ([triggerEvent isEqualToString:@"joinwj"]) { // v4.8.0 新增的问卷跳转
            NSDictionary *params = @{@"linkURL" : kNewSurvey(self.detailModel.eventValue)};
            UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadController:params];
            [self.navigationController pushViewController:vc animated:YES];
        } else if ([triggerEvent isEqualToString:@"completeTask"]) { // 5.0.0新增 跳转福利社
            SEGActivitySignViewController *signVC = [[SEGActivitySignViewController alloc] init];
            signVC.actId = ValueToString(self.detailViewModel.homeSignActId);
            signVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:signVC animated:YES];
        }
    } error:^(NSError * _Nullable error) {
        if (error.code == kActicityErrorCode_NoAuth) {
            [self showNothAlterView];
            return;
        }
        [SEGAlertView showTmepMessageWithMessage:error.localizedDescription];
    }];
}

@end

